
# Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved.
# This component and the accompanying materials are made available
# under the terms of the License "Eclipse Public License v1.0"
# which accompanies this distribution, and is available
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
#
# Initial Contributors:
# Nokia Corporation - initial contribution.
#
# Contributors:
#
# Description: 
#
# planb.target module

'''
The target module defines the base classes for different types of build
artifact.

Each artifact in a build is a target which can either be provided at the start
(for example, source files) or which is generated by the build.

Generated targets are also often classified as "releasable" (meaning useful
after the build) or "intermediate" (meaning only useful as a step in the build).

We should also consider non-file targets at some point... for example, services
that can provide input data to a build or record build data.
'''

# constants

# objects

class Base(object):
	'''Base class for targets.
	
	Represents targets that have 0 or more inputs, 0 or more outputs and
	an action that can generate the outputs from the inputs.
	'''
	
	def __init__(self):
		self.generated_dependency_file = None
		self.inputs = []
		self.outputs = []
		self.run = 'true'    # a command that always succeeds
		
	def add_input(self, input):
		# here we assume input is a string, but really it should be either
		# a string (which we assume is a filename?) or another target.
		self.inputs.append(input)
	
	def add_inputs(self, inputs):
		self.inputs.extend(inputs)
			
	def add_output(self, output, releasable=True):
		# here we assume output is a string, but really it should be either
		# a string (which we assume is a filename?) or another target.
		self.outputs.append(Output(output, releasable))
			
	def action(self, command):
		# here we assume command is a string, but really it should be either
		# a string (which we assume is a shell command?) or an object of some
		# type...
		self.run = command
	
	def generated_dependencies(self, depfile):
		# not quite sure where this should go. maybe generated dependencies
		# should just be another output target?
		self.generated_dependency_file = depfile
		
	def finalise(self):
		# maybe not for the base class. it reflects a need to sometimes build
		# up a whole load of different settings in a target and then have a
		# single method which pulls all the settings together in some way.
		pass

class Input(object):
	# this was going to be a target with no-inputs (i.e. a source file) but
	# it isn't used anywhere so far. see the comment on "add_input" above.
	pass

class Output(object):
	# this is just a simple container so far.
	# see the comment on "add_output" above.
	def __init__(self, filename, releasable=True):
		self.filename = filename
		self.releasable = releasable

# the next 3 classes reflect the current need to split makefiles into phases.
# they should only exist if they offer some understandable functionality.
	
class Bitmap(Base):
	'''Represents a bitmap of some kind.'''
	def __init__(self):
		Base.__init__(self)
		self.phase = 'BITMAP'
		self.title = 'planb.bitmap'

class Resource(Base):
	'''Represents a resource of some kind.'''
	def __init__(self):
		Base.__init__(self)
		self.phase = 'RESOURCE'
		self.title = 'planb.resource'

class Target(Base):
	'''Represents a generic target of some kind.
	
	Originally this was the base class. I think it should be called something
	else or should not exist as it is confusing.'''
	def __init__(self):
		Base.__init__(self)
		self.phase = 'ALL'
		self.title = 'planb.target'

# end of the planb.target module
